<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="../templates/principal.xhtml">

    <ui:define name="content" id="content">
        <h:form id="frmOrgaoDocumento">
            <p:panel id="panel" header="Bem Vindo ao Cadastro de Orgão - Lista de Documentos">
                <p:growl id="messages" life="5000" />

                <p:dataTable id="tabOrgaoDocumento" widgetVar="wtabOrgaoDocumento" var="orgaoDocumento" value="#{orgaoDocumentoBean.lazyModel}" 
                             lazy="true" paginator="true" rows="12" paginatorPosition="top"
                             emptyMessage="Nenhum Registro Retornado ..." filterEvent="enter">

                    <p:column headerText="Orgão" sortBy="#{orgaoDocumento.dscOrgao}" filterBy="#{orgaoDocumento.dscOrgao}" style="text-align: left;">
                        <h:outputText value="#{orgaoDocumento.dscOrgao}" />
                    </p:column>

                    <p:column headerText="Assunto" sortBy="#{orgaoDocumento.dscAssunto}" filterBy="#{orgaoDocumento.dscAssunto}" style="text-align: left;">
                        <h:outputText value="#{orgaoDocumento.dscAssunto}" />
                    </p:column>

                    <p:column style="width: 100px;">
                        <h:panelGrid columns="4" styleClass="actions" cellpadding="0">
                            <p:commandButton id="selectButtonOrgaoDocumento" update=":frmOrgaoDocumento:panel :frmOrgaoDocumento:display :frmOrgaoDocumento:messages" 
                                             icon="ui-icon-search" title="Visualizar // Alterar Orgão - Lista de Documentos" oncomplete="PF('orgaoDocumentoDialog').show()">
                                <f:setPropertyActionListener value="#{orgaoDocumento}" target="#{orgaoDocumentoBean.selectedOrgaoDocumento}" />
                                <f:setPropertyActionListener value="#{false}" target="#{orgaoDocumentoBean.salvar}" />
                            </p:commandButton>

                            <p:commandButton id="excluirButtonOrgaoDocumento" update=":frmOrgaoDocumento:panel :frmOrgaoDocumento:messages" 
                                             icon="ui-icon-trash" title="Excluir Orgão - Lista de Documentos" oncomplete="PF('confirmation').show()">
                                <f:setPropertyActionListener value="#{orgaoDocumento}" target="#{orgaoDocumentoBean.selectedOrgaoDocumento}" />
                            </p:commandButton>
                        </h:panelGrid>
                    </p:column>

                    <f:facet name="footer">
                        <div style="text-align: left;">
                            <p:commandButton id="incluirButtonBaco" actionListener="#{orgaoDocumentoBean.preparaInserir}" 
                                             update=":frmOrgaoDocumento:panel :frmOrgaoDocumento:messages" value="Novo Orgão - Lista de Documentos"
                                             icon="ui-icon-pencil" title="Cadastrar Novo Orgão - Lista de Documentos" oncomplete="PF('orgaoDocumentoDialog').show()" />
                        </div>
                    </f:facet>
                </p:dataTable>

                <p:dialog id="dialog" header="Detalhes Orgão - Lista de Documentos" widgetVar="orgaoDocumentoDialog" resizable="true"
                          width="700" showEffect="explode" hideEffect="explode">

                    <h:panelGrid id="display" columns="2" style="margin-bottom:50px; text-align: left;">
                        <h:outputText value="Orgão:" />
                        <p:inputText id="inOrgao" value="#{orgaoDocumentoBean.selectedOrgaoDocumento.dscOrgao}" style="width:500px; font-weight:bold" maxlength="50" />

                        <h:outputText value="Assunto:" />
                        <p:inputText id="inAssunto" value="#{orgaoDocumentoBean.selectedOrgaoDocumento.dscAssunto}" style="width:500px; font-weight:bold" maxlength="50" />

                        <h:outputText value="Lista de Documentos:" />
                        <p:pickList id="pojoPickList" value="#{orgaoDocumentoBean.tipoDocumentos}" var="lista" effect="bounce"
                                    itemValue="#{lista}" itemLabel="#{lista.dscDocumento}" converter="lista"
                                    showSourceFilter="true" showTargetFilter="true" filterMatchMode="contains" >

                            <f:facet name="sourceCaption">Documentos</f:facet>
                            <f:facet name="targetCaption">Lista de Documentos</f:facet>

                            <p:column style="width:75%; font-weight:bold;">
                                #{lista.dscDocumento}
                            </p:column>
                        </p:pickList>

                        <f:facet name="footer">
                            <br />
                            <p:commandButton value="Salvar - incluir" update=":frmOrgaoDocumento:panel :frmOrgaoDocumento:messages" rendered="#{orgaoDocumentoBean.salvar}"
                                             actionListener="#{orgaoDocumentoBean.inserir}" oncomplete="PF('orgaoDocumentoDialog').hide()" />
                            <p:commandButton value="Salvar - alterar" update=":frmOrgaoDocumento:panel :frmOrgaoDocumento:messages" rendered="#{!orgaoDocumentoBean.salvar}"
                                             actionListener="#{orgaoDocumentoBean.alterar}" oncomplete="PF('orgaoDocumentoDialog').hide()" />
                        </f:facet>
                    </h:panelGrid>
                </p:dialog>

                <p:dialog header="Confirma a Exclusão desse Orgão - Lista de Documentos?" widgetVar="confirmation">

                    <p:commandButton value="Sim" update=":frmOrgaoDocumento:panel :frmOrgaoDocumento:messages" oncomplete="PF('confirmation').hide(), PF('orgaoDocumentoDialog').hide()"
                                     actionListener="#{orgaoDocumentoBean.excluir}" />
                    <p:commandButton value="Não" onclick="PF('confirmation').hide()" type="button" />

                </p:dialog>
            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>